<template>
  <div>
    <Header @searchList="searchList" />
    <div class="main">
      <el-row>
        <div class="btnBox">
          <el-button class="btn" @click="addTask">
            <i class="el-icon-circle-plus-outline" />
            新建
          </el-button>
        </div>
      </el-row>
      <el-table empty-text="暂无数据" :data="list">
        <el-table-column label="序号">
          <template v-slot="{$index}">
            {{ ($index + 1) + (queryParams.pageIndex - 1) * 10 }}
          </template>
        </el-table-column>

        <el-table-column prop="taskCode" label="工单编号" />

        <el-table-column prop="innerCode" label="设备编号" />
        <el-table-column prop="taskType.typeName" label="工单类型" />
        <el-table-column prop="createType" label="工单方式">
          <template v-slot="{row}">
            <span v-if="row.createType === 1">手动</span>
            <span v-else>自动</span>
          </template>
        </el-table-column>
        <el-table-column prop="taskStatus" label="工单状态">
          <template v-slot="{row}">
            <span v-if="row.taskStatus">{{ typeIdArr[row.taskStatus] }}</span>
            <span v-else>无</span>
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="运维人员" />
        <el-table-column prop="createTime" label="创建日期" />
        <el-table-column prop="innerCode" label="操作" width="200px">
          <template v-slot="{row}">
            <el-button size="mini" type="text" @click="seeMoreInfo(row.taskId)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-row v-if="list.length > 0" align="middle" justify="space-between" style="height: 60px" type="flex">
        <span style="color: #dbdfe5">共{{ totalCount }}条记录  第 {{ queryParams.pageIndex }}/{{ totalPage }} 页</span>
        <el-pagination
          :current-page="queryParams.pageIndex"
          :page-size="queryParams.pageSize"
          :total="+total"
          layout="prev, next"
          next-text="下一页"
          prev-text="上一页"
          @current-change="changePage"
        />
      </el-row>
    </div>
    <el-dialog class="dialog" width="630px" title="工单详情" :visible.sync="showInfoDialog">
      <div class="dialog-wrapper">
        <div class="dialog-content">
          <img src="" alt="图片">
          <div class="dialog-info">
            <div class="dialog-info-left">
              <p>设备编号：{{ infoList.innerCode }}</p>
              <p>取消日期：{{ infoList.updateTime }}</p>
              <p>工单类型：</p>
              <p>取消原因：{{ infoList.desc }}</p>
            </div>
            <div class="dialog-info-right">
              <p>创建日期：{{ infoList.createTime }}</p>
              <p>运维人员：{{ infoList.userName }}</p>
              <p>工单方式：{{ infoList.createType === 1 ? '手动':'自动' }}</p>
            </div>
          </div>
        </div>
      </div>
      <el-button>重新创建</el-button>
    </el-dialog>
    <el-dialog class="dialog" width="630px" title="新增工单" :visible.sync="showDialog">
      <el-form label-width="120px">
        <el-form-item label="设备编号">
          <el-input v-model="createFrom.innerCode" size="small" />
        </el-form-item>
        <el-form-item label="工单类型">
          <el-input v-model="createFrom.productType" size="small" />
        </el-form-item>
        <el-form-item label="运维人员">
          <el-input v-model="createFrom.userId" size="small" />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="createFrom.desc" type="textarea" size="small" />
        </el-form-item>
        <el-form-item>
          <el-button size="mini">取消</el-button>
          <el-button size="mini" type="primary" @click="submit">确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { typeIdArr } from '@/api/constants'
import Header from '@/components/Hander/index.vue'
import { getTasskList, getTaskInfo, createTask } from '@/api/operation'
export default {
  components: { Header },
  data() {
    return {
      list: [],
      typeId: [],
      queryParams: {
        pageIndex: 1,
        pageSize: 10,
        isRepair: true
      },
      createFrom: {
        assignorId: 10,
        createType: 1,
        innerCode: '01000045',
        productType: 3,
        userId: 1,
        desc: 'cnmd',
        details: []
      },
      infoList: [],
      showInfoDialog: false,
      showDialog: false,
      total: 0,
      totalPage: '',
      totalCount: '',
      status: null
    }
  },
  created() {
    this.getTasskList()
    this.typeIdArr = typeIdArr
  },
  methods: {
    async searchList(status) {
      this.queryParams.pageIndex = 1
      this.status = status
      this.getTasskList(status)
    },
    async submit() {
      await createTask(this.createFrom)
    },
    async seeMoreInfo(id) {
      this.showInfoDialog = true
      const res = await getTaskInfo(id)
      this.infoList = res
      console.log(this.infoList)
      // console.log(this.infoList.taskType.typeName)
    },
    addTask() {
      this.showDialog = true
    },
    async changePage(page) {
      this.queryParams.pageIndex = page
      if (this.status) {
        await this.getTasskList(this.status)
      } else {
        await this.getTasskList()
      }
    },
    async getTasskList(status) {
      if (status) {
        const res = await getTasskList({
          ...this.queryParams,
          status
        })
        this.list = res.currentPageRecords
        this.total = res.totalCount
        this.totalPage = res.totalPage
        this.totalCount = res.totalCount
      } else {
        const res = await getTasskList(this.queryParams)
        this.list = res.currentPageRecords
        this.total = res.totalCount
        this.totalPage = res.totalPage
        this.totalCount = res.totalCount
      }
    }
  }
}
</script>

<style scoped>
.main{
  width: 100%;
  height: 693px;
  padding: 20px;
  background-color: #fff;
  margin-bottom: 70px;
}
.btnBox {
  padding-bottom: 10px;
}
.btn {
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  width: 80px !important;
  height: 36px;
  padding: 0;
  background: linear-gradient(135deg, #ff9743, #ff5e20) !important;
  border: none;
  color: white;
}
::v-deep .el-pagination button {
width: 70px;
height: 32px;
margin: 0 16px;
border-radius: 2px;
background-color: #d5ddf8;
}

::v-deep .btn-prev:disabled {
background: #edf0f9;
}
::v-deep .dialog{
  border-radius: 30px;
}
.dialog-info{
  display: flex;
}
</style>
